<template>
    <div class="container">
        <div class="title">
            <span>修改</span>
            <span class="back" @click="back">
        <i class="iconfont icon-fanhui"></i> 返回
      </span>
        </div>
        <el-divider></el-divider>
        <br/>
        <el-form label-width="140px"
                 :model="form"
                 status-icon
                 ref="form"
                 @submit.native.prevent>
            <el-form-item label="返佣" prop="commission">
                <el-input size="medium" v-model="form.invite_money" placeholder="请填写返佣"></el-input>
            </el-form-item>
            <el-form-item label="返佣比例/%" prop="commission">
                <el-input size="medium" v-model="form.commission" placeholder="请填写返佣比例"></el-input>
            </el-form-item>
            <el-form-item label="助理数量" prop="assistant_number">
                <el-input size="medium" v-model="form.assistant_number" placeholder="请填写助理数量"></el-input>
            </el-form-item>
            <el-form-item label="助理返佣比例/%" prop="assistant_commission">
                <el-input size="medium" v-model="form.assistant_commission" placeholder="请填写助理返佣比例"></el-input>
            </el-form-item>
            <el-form-item class="submit">
                <el-button type="primary" @click="submitForm('form')">保 存</el-button>
                <el-button @click="resetForm('form')">重 置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import partner from '@/models/partner'

export default {
  props: {
    cityId: {
      type: Number,
    },
  },
  data() {
    return {
      form: {
        invite_money: '',
        commission: '',
        assistant_number: '',
        assistant_commission: '',
        status: '',
      },
    }
  },
  mounted() {
    this.getInfo()
  },
  methods: {
    // 获取详情
    async getInfo() {
      const info = await partner.getCityInfo(this.cityId)
      this.form = {
        commission: info.commission,
        assistant_number: info.assistant_number,
        assistant_commission: info.assistant_commission,
        status: String(info.status),
      }
    },
    // eslint-disable-next-line no-unused-vars
    async submitForm(formName) {
      const self = this
      // eslint-disable-next-line no-unused-vars
      const info = {
        id: this.cityId,
        commission: self.form.commission,
        assistant_number: self.form.assistant_number,
        assistant_commission: self.form.assistant_commission,
        status: self.form.status,
      }
      try {
        // eslint-disable-next-line no-unused-vars
        const res = await partner.updateCity(info)
        if (res.error_code === 0) {
          this.$message.success(`${res.msg}`)
          this.back()
        }
      } catch (error) {
        console.log(error)
      }
    },
    // 重置表单
    resetForm() {
      this.getInfo()
    },
    back() {
      this.$emit('editClose')
    },
  },
}
</script>

<style lang="scss" scoped>
    .el-divider--horizontal {
        margin: 0
    }

    .container {
        .title {
            height: 59px;
            line-height: 59px;
            color: $parent-title-color;
            font-size: 16px;
            font-weight: 500;
            text-indent: 40px;

            .back {
                float: right;
                margin-right: 40px;
                cursor: pointer;
            }
        }

        .wrap {
            padding: 20px;
        }

        .submit {
            float: left;
        }
    }
</style>
